using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class ShopPage : MonoBehaviour
{
    public Button btn;

    public GameObject mainPage;

    public Button diamonBtn;

    public Button glodBtn;

    public TextMeshProUGUI glodRedPoint;
    public TextMeshProUGUI diamonRedPoint;
    
    
    // Start is called before the first frame update
    void Start()
    {
        btn.onClick.AddListener(OnClick);
        glodBtn.onClick.AddListener(OnGlodBtnClick);
        diamonBtn.onClick.AddListener(OnDiamonBtnClick);
        
        RedPointMgr.Instance.GetNode(ERedPoint.Shop_Diamon).AddOnRedPointStateChangeListener(node =>
        {
            diamonRedPoint.transform.parent.gameObject.SetActive(node.RedCount>0);
            diamonRedPoint.text = node.RedCount.ToString();
        });
        
        RedPointMgr.Instance.GetNode(ERedPoint.Shop_Glod).AddOnRedPointStateChangeListener(node =>
        {
            glodRedPoint.transform.parent.gameObject.SetActive(node.RedCount>0);
            glodRedPoint.text = node.RedCount.ToString();
        });
    }

    private void OnDiamonBtnClick()
    {
        ShopMgr.Instance.dimongData.isVisible = false;
        ShopMgr.Instance.RefreshRedPoint();
    }

    private void OnGlodBtnClick()
    {
        ShopMgr.Instance.gloadData.isVisible = false;
        ShopMgr.Instance.RefreshRedPoint();
    }

    private void OnClick()
    {
        gameObject.SetActive(false);
        mainPage.SetActive(true);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
